//
//  GetOrderGroupVm.swift
//  Pods
//
//  Created by eme on 2017/4/5.
//
//
/*
 * 查看组合商品ViewModel
 */
import RxSwift
import NetWorkCore
import SwiftyJSON
import ModelProtocol

class GetOrderGroupVm{
    
    let getGroupModel = PublishSubject<String>()
    
    let backDate = PublishSubject<GroupModel>()
    
    let disposeBag = DisposeBag()
    
    let error = PublishSubject<MikerError>()
    
    let refreshing = Variable(false)
    
    var pdid = ""
    
    init (){
        
        let request = getGroupModel.map{ orderid in
            
            return MineApi.getOrderGroup(orderid: orderid, pdid: self.pdid)
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForObj(GroupModel.self).shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            
            switch result{
                
            case .success(let data):
                
                self.backDate.onNext(data)
                
            case.failure(let error):
                
                self.error.onNext(error)
                
            }
            
        }).addDisposableTo(disposeBag)
    }
    
}
